package com.xiaoyu.lanling.feature.serverpush.event

import `in`.srain.cube.request.JsonData
import androidx.fragment.app.FragmentActivity
import com.xiaoyu.base.app.App
import com.xiaoyu.base.serverpush.event.ServerPushBaseEvent
import com.xiaoyu.base.utils.extensions.isDead
import com.xiaoyu.lanling.event.charming.CharmingLevelUpEvent
import com.xiaoyu.lanling.feature.charming.CharmLogger
import com.xiaoyu.lanling.feature.charming.CharmingLevel
import com.xiaoyu.lanling.feature.charming.CharmingLevelUpDialog

class CharmingLevelUpPush(jsonData: JsonData) : ServerPushBaseEvent(jsonData) {
    val data = CharmingLevel(jsonData)
    override fun takeAction() {
        CharmLogger.logPushReceived()
        CharmingLevelUpEvent(data).post()
        setComplete()
        val topActivity = (App.getInstance().topActivity as? FragmentActivity) ?: return
        if (topActivity.isDead()) {
            return
        }
        CharmingLevelUpDialog.show(topActivity.supportFragmentManager, data)
    }
}